package org.phalanx.client.menus;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenuItem;

import org.phalanx.client.mapeditor.PhalanxMapEditorPanel;

public class DisplayMenuAction implements ActionListener {
	private PhalanxMapEditorPanel masterPanel;
	
	public DisplayMenuAction(PhalanxMapEditorPanel masterPanel){
		this.masterPanel = masterPanel;
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() instanceof JMenuItem){
			String actionCommand = ((JMenuItem)e.getSource()).getName();
			
			if (actionCommand.equalsIgnoreCase("drawgridlines")){
				JCheckBoxMenuItem j = (JCheckBoxMenuItem)e.getSource();
				masterPanel.getDisplayContainer().getMapViewObject().setIsGridDrawn(j.isSelected());
			}
			else if (actionCommand.equalsIgnoreCase("zoomin")){
				Double zoomLevel = masterPanel.getDisplayContainer().getMapViewObject().getZoomLevel();
				masterPanel.getDisplayContainer().getMapViewObject().setZoomLevel(zoomLevel + .5);
			}
			else if (actionCommand.equalsIgnoreCase("zoomout")){
				Double zoomLevel = masterPanel.getDisplayContainer().getMapViewObject().getZoomLevel();
				masterPanel.getDisplayContainer().getMapViewObject().setZoomLevel(zoomLevel - .5);
			}
			else if (actionCommand.equalsIgnoreCase("drawbuildpoints")) {
				JCheckBoxMenuItem j = (JCheckBoxMenuItem)e.getSource();
				masterPanel.getDisplayContainer().getMapViewObject().setDrawBuildPoints(j.isSelected());
			}
		}
		
	}

}
